//
//  HomeTableViewCell.m
//  ScrollViewDemo
//
//  Created by SmartStrategy on 2019/4/8.
//  Copyright © 2019 SmartStrategy. All rights reserved.
//

#import "HomeTableViewCell.h"
#import "PageView.h"
#import "../HomeSubController.h"


@interface HomeTableViewCell ()

@property (nonatomic,strong) PageView *pageView;

@end

@implementation HomeTableViewCell


- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self createUI];
    }
    return self;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createUI];
    }
    return self;
}

- (void)createUI{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    [self.contentView addSubview:self.pageView];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (PageView *)pageView{
    if (_pageView == nil) {
        _pageView = [[PageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-44-40-83) withTitles:@[@"订单",@"状态"] withViewControllers:@[@"HomeSubController",@"HomeSubController"]];
    }
    return _pageView;
}

- (void)setIsRefresh:(BOOL)isRefresh {
    _isRefresh = isRefresh;
    
    [self.pageView.strongArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if ([obj isKindOfClass:[HomeSubController class]]) {
            HomeSubController *vc = (HomeSubController *)obj;
            vc.isRefresh = isRefresh;
        }
    }];
}

- (void)setCellCanScroll:(BOOL)cellCanScroll {
    _cellCanScroll = cellCanScroll;
    
    [self.pageView.strongArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if ([obj isKindOfClass:[HomeSubController class]]) {
            HomeSubController *vc = (HomeSubController *)obj;
            vc.vcCanScroll = cellCanScroll;
            if (!cellCanScroll) {
                vc.tableView.contentOffset = CGPointZero;
            }
        }
    }];
}

@end
